<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增排班')" />
    <th:block th:include="include :: datetimepicker-css" />
<!--    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>-->
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-people-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">部门：</label>
            <div class="col-sm-8">
                <select id="deptId" name="deptId" class="form-control">
                    <!--                        <option th:each="post:${deptList}" th:value="${post.deptId}" th:text="${post.deptName}" th:disabled="${post.status == '1'}"></option>-->
                </select>
            </div>
        </div>
        <table>
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date" >
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_1" class="form-control laydate-demo-2" name="riqi" placeholder="--请选择日期--">
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" >
                                <!--                                    <option th:each="post:${userList}" th:value="${post.userId}" th:text="${post.userName}" th:disabled="${post.userStatus == '1'}"></option>-->
                            </select>
                        </div>
                    </div>
                </td>
            </tr>
<!--            <tr  th:each="count, iterStat : ${#numbers.sequence(1, 2)}">-->
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_2" class="form-control laydate-demo-2" name="riqi" placeholder="yyyy-MM-dd" disabled>
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" ></select>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_3" class="form-control laydate-demo-2" name="riqi" placeholder="yyyy-MM-dd" disabled>
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" ></select>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_4" class="form-control laydate-demo-2" name="riqi" placeholder="yyyy-MM-dd" disabled>
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" ></select>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_5" class="form-control laydate-demo-2" name="riqi" placeholder="yyyy-MM-dd" disabled>
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" ></select>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_6" class="form-control laydate-demo-2" name="riqi" placeholder="yyyy-MM-dd" disabled>
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" ></select>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input type="text" id="dutyDate_7" class="form-control laydate-demo-2" name="riqi" placeholder="yyyy-MM-dd" disabled>
                            </div>
                        </div>
                    </div>
                </td>
                <td >
                    <div class="form-group"  style="width: 326px">
                        <label class="col-sm-3 control-label"  style="width: 82px">值班人：</label>
                        <div class="col-sm-8">
                            <select class="form-control dutyPerson" name="dutyPersonId" ></select>
                        </div>
                    </div>
                </td>
            </tr>

        </table>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<!--<script th:src="@{/layui/layui.all.js}"></script>-->
<script th:inline="javascript">
    /**
     * 选择部门就查询出该部门的所有员工
     */
    $(document).ready(function() {//页面加载时运行此函数 放在最前端
        $.ajax({
            url: ctx + "system/dept/getDeptList",
            type: 'GET',
            success:function (data) {
                <!--清空下拉框中的缓存-->
                $("#deptId").empty();
                <!--避免下拉框的值不变-->
                $("#deptId").append("<option value=''>请选择部门</option>");
                <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
                for (var i = 0; i < data.length; i++){
                    $("#deptId").append("<option value='" + data[i].deptId + "'>" + data[i].deptName + "</option>");
                }
            }
        });
        $("#deptId").change(function () {//同上面一样
            // alert($("#deptId").val())
            $.ajax({
                url: ctx + "system/user/getAllUserByDeptId",
                type: 'GET',
                data: {
                    //注意：此处传递的值的名字id必须和后端接受的相同，否则接收不到
                    id: $("#deptId").val(),
                },
                success:function (data) {
                    $(".dutyPerson").empty();
                    $(".dutyPerson").append("<option value=''>请选择值班人</option>");
                    for (var i = 0; i < data.length; i++){
                        $(".dutyPerson").append("<option value='" + data[i].userId + "'>" + data[i].userName + "</option>");
                    }
                }
            });
        });

    })

    var prefix = ctx + "system/people"
    $("#form-people-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            submit();
            $.operate.save(prefix + "/addDatePeople", $('#form-people-add').serialize());
        }
    }

    $("input[name='dutyDate']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    var dutyDateList=[];

    $(function(){
        <!-- laydate示例 -->
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            laydate.render({
                elem: '#dutyDate_1',
                type: 'date',
                done: function(value, date){
                    var newData=new Date(date.year,date.month,date.date);
                    // console.log(value); //得到日期生成的值，如：2017-08-18
                    // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                    dutyDateList.push(newData)
                    newData.setDate(newData.getDate()+1)
                    dutyDateList.push(newData)
                    laydate.render({
                        elem: '#dutyDate_2',
                        value: newData
                    });
                    newData.setDate(newData.getDate()+1)
                    dutyDateList.push(newData)
                    laydate.render({
                        elem: '#dutyDate_3',
                        value: newData
                    });
                    newData.setDate(newData.getDate()+1)
                    dutyDateList.push(newData)
                    laydate.render({
                        elem: '#dutyDate_4',
                        value: newData
                    });
                    newData.setDate(newData.getDate()+1)
                    dutyDateList.push(newData)
                    laydate.render({
                        elem: '#dutyDate_5',
                        value: newData
                    });
                    newData.setDate(newData.getDate()+1)
                    dutyDateList.push(newData)
                    laydate.render({
                        elem: '#dutyDate_6',
                        value: newData
                    });
                    newData.setDate(newData.getDate()+1)
                    dutyDateList.push(newData)
                    laydate.render({
                        elem: '#dutyDate_7',
                        value: newData
                    });
                }
            });
        });
    });
    var dutyPerSonList=[];
    var submit=function () {
        $('.dutyPerson').each(function(index, el) {
            console.log($(this))
            // if($(this).prop('checked')){
            //     ids.push($(this).val())
            //     console.log(ids)
            // }
        });
    }


</script>
</body>
</html>